import express from 'express'
import cors from 'cors'
import mongoose, { ConnectOptions } from 'mongoose';

import authRoutes from './routes/authRouter'
import articleRoutes from './routes/articleRouter'
import exchangeRateRoutes from './routes/exchangeRateRouter'
const app = express();

app.use(express.json());
app.use(cors());
app.use('/api/auth', authRoutes)
app.use('/api/articles', articleRoutes)
app.use('/api/exchangeRates', exchangeRateRoutes)

const startServer = async () => {
    try {
        // mongodb://username:password@192.168.56.102:27017/currencyeg
        await mongoose.connect('mongodb://192.168.56.102:27017/currencyeg', {
            // useNewUrlParser: true,
            // useUnifiedTopology: true,
        } as ConnectOptions)

        console.log('Connected to MongoDB')

        app.listen(3000, () => {
            console.log('Server is running on port 3000')
        });
    } catch (error) {
        console.error('Error caused:', error)
        process.exit(1)
    }
}


startServer()